/**
 * Title: jFamilyTree
 * Description: jFamilyTree mutable
 * Version: provider
 * Copyright: (c) 2001-2008
 * Terms of use:see license agreement at http://treebolic.sourceforge.net/en/license.htm
 * Author: Bernard Bou
 * Company: bsys
 * Update: Mon Mar 10 00:00:00 CEST 2008
 */
package jFamilyTree.model;

import java.util.List;

/**
 * Model dump
 * 
 * @author Bernard Bou
 */
public class ModelDump
{
	/**
	 * Stringify tree
	 * 
	 * @param thisTree
	 *        tree
	 * @return string for tree
	 */
	static public String toString(Tree thisTree)
	{
		StringBuffer thisBuffer = new StringBuffer();
		thisBuffer.append("NODES\n");
		thisBuffer.append(toString(thisTree.getRoot(), 0));
		thisBuffer.append("EDGES\n");
		thisBuffer.append(toString(thisTree.getEdges()));
		return thisBuffer.toString();
	}

	/**
	 * Stringify node and children
	 * 
	 * @param thisNode
	 *        node
	 * @param thisLevel
	 *        level
	 * @return string for node
	 */
	static public String toString(INode thisNode, int thisLevel)
	{
		StringBuffer thisBuffer = new StringBuffer();
		for (int i = 0; i < thisLevel; i++)
			thisBuffer.append('\t');

		if (thisNode == null)
			thisBuffer.append("[null node]");
		else
		{
			thisBuffer.append("#");
			thisBuffer.append(thisNode.getId());
			thisBuffer.append(" '");
			thisBuffer.append(thisNode.toString());
			thisBuffer.append("' ^");
			INode thisParent = thisNode.getParent();
			if (thisParent != null)
			{
				thisBuffer.append("#");
				thisBuffer.append(thisParent.getId());
			}
			thisBuffer.append("\n");
			for (INode thisChildNode : thisNode.getChildren())
				thisBuffer.append(toString(thisChildNode, thisLevel + 1));
		}
		return thisBuffer.toString();
	}

	/**
	 * Stringify edge list
	 * 
	 * @param thisEdgeList
	 *        edge list
	 * @return string for edge list
	 */
	static public String toString(List<IEdge> thisEdgeList)
	{
		StringBuffer thisBuffer = new StringBuffer();
		if (thisEdgeList != null)
			for (IEdge thisEdge : thisEdgeList)
			{
				thisBuffer.append(thisEdge.toString());
				thisBuffer.append("\n");
			}
		return thisBuffer.toString();
	}

	/**
	 * Stringify settings
	 * 
	 * @param theseSettings
	 *        settings
	 * @return string for settings
	 */
	static public String toString(Settings theseSettings)
	{
		StringBuffer thisBuffer = new StringBuffer();
		thisBuffer.append("BackColor=" + Utils.colorToString(theseSettings.theBackColor) + "\n");
		thisBuffer.append("ForeColor=" + Utils.colorToString(theseSettings.theForeColor) + "\n");
		thisBuffer.append("BackgroundImage=" + theseSettings.theBackgroundImage + "\n");
		thisBuffer.append("FontFace=" + theseSettings.theFontFace + "\n");
		thisBuffer.append("FontSize=" + theseSettings.theFontSize + "\n");
		thisBuffer.append("FontSizeStep=" + theseSettings.theFontSizeStep + "\n");
		thisBuffer.append("Orientation=" + theseSettings.theOrientation + "\n");
		thisBuffer.append("Expansion=" + theseSettings.theExpansion + "\n");
		thisBuffer.append("Sweep=" + theseSettings.theSweep + "\n");
		thisBuffer.append("PreserveOrientationFlag=" + theseSettings.thePreserveOrientationFlag + "\n");
		thisBuffer.append("HyperbolicEdgesFlag=" + theseSettings.theHyperbolicEdgesFlag + "\n");
		thisBuffer.append("HasToolbarFlag=" + theseSettings.theHasToolbarFlag + "\n");
		thisBuffer.append("HasStatusbarFlag=" + theseSettings.theHasStatusbarFlag + "\n");
		thisBuffer.append("HasPopUpMenuFlag=" + theseSettings.theHasPopUpMenuFlag + "\n");
		thisBuffer.append("HasToolTipFlag=" + theseSettings.theHasToolTipFlag + "\n");
		thisBuffer.append("ToolTipDisplaysContentFlag=" + theseSettings.theToolTipDisplaysContentFlag + "\n");
		thisBuffer.append("FocusOnHoverFlag=" + theseSettings.theFocusOnHoverFlag + "\n");
		thisBuffer.append("Focus=" + theseSettings.theFocus + "\n");
		thisBuffer.append("XMoveTo=" + theseSettings.theXMoveTo + "\n");
		thisBuffer.append("YMoveTo=" + theseSettings.theYMoveTo + "\n");
		thisBuffer.append("XShift=" + theseSettings.theXMoveTo + "\n");
		thisBuffer.append("YShift=" + theseSettings.theYMoveTo + "\n");
		thisBuffer.append("NodeBackColor=" + Utils.colorToString(theseSettings.theNodeBackColor) + "\n");
		thisBuffer.append("NodeForeColor=" + Utils.colorToString(theseSettings.theNodeForeColor) + "\n");
		thisBuffer.append("DefaultNodeImage=" + theseSettings.theDefaultNodeImage + "\n");
		thisBuffer.append("TreeEdgeColor=" + Utils.colorToString(theseSettings.theTreeEdgeColor) + "\n");
		thisBuffer.append("TreeEdgeStyle=" + toString(theseSettings.theTreeEdgeStyle) + "\n");
		thisBuffer.append("DefaultTreeEdgeImage=" + theseSettings.theDefaultTreeEdgeImage + "\n");
		thisBuffer.append("EdgeColor=" + Utils.colorToString(theseSettings.theEdgeColor) + "\n");
		thisBuffer.append("EdgeStyle=" + toString(theseSettings.theEdgeStyle) + "\n");
		thisBuffer.append("DefaultEdgeImage=" + theseSettings.theDefaultEdgeImage + "\n");
		if (theseSettings.theMenu == null)
			thisBuffer.append("Menu=null");
		else
			for (MenuItem thisMenuItem : theseSettings.theMenu)
			{
				thisBuffer.append("MenuItem");
				thisBuffer.append(" action=" + thisMenuItem.theAction);
				thisBuffer.append(" link=" + thisMenuItem.theLink);
				thisBuffer.append(" target=" + thisMenuItem.theMatchTarget);
				thisBuffer.append(" scope=" + thisMenuItem.theMatchScope);
				thisBuffer.append(" mode=" + thisMenuItem.theMatchMode);
				thisBuffer.append(" label=" + thisMenuItem.theLabel);
			}
		return thisBuffer.toString();
	}

	/**
	 * Stringify style
	 * 
	 * @param thisStyle
	 *        style
	 * @return string for style
	 */
	static public String toString(Integer thisStyle)
	{
		StringBuffer thisBuffer = new StringBuffer();
		String[] theseStrings = Utils.toStrings(thisStyle);
		thisBuffer.append("hidden=" + theseStrings[0]);
		thisBuffer.append(" stroke=" + theseStrings[1]);
		thisBuffer.append(" fromterminator=" + theseStrings[2]);
		thisBuffer.append(" toterminator=" + theseStrings[3]);
		return thisBuffer.toString();
	}
}
